package com.digua.frame.plugin.config;

import com.lionbridge.skywalking.extension.util.TraceUtils;
import org.apache.skywalking.apm.agent.core.conf.Config.Agent;
import org.apache.skywalking.apm.util.StringUtil;

/**
 * @description:
 * @author: wangzhilong
 * @date: 2021/10/20
 **/
public class Constants {

    private static final String KEEP_REPORT_KEY = "skywalking.agent.keep_report";
    private static final String SERVICE_NAME_KEY = "skywalking.agent.service_name";
    private static final String INSTANCE_NAME_KEY = "skywalking.agent.instance_name";
    private static final String HOST_KEY = "skywalking.agent.host";
    public static boolean KEEP_REPORT = true;
    public static String HOST = "host:N/A";

    static {
        String host = System.getProperty("skywalking.agent.host");
        if (StringUtil.isNotEmpty(host)) {
            HOST = host;
        }

        Agent.KEEP_TRACING = true;
        String keepReport = System.getProperty("skywalking.agent.keep_report");
        if (StringUtil.isNotEmpty(keepReport) && "false".equalsIgnoreCase(keepReport)) {
            KEEP_REPORT = false;
        }

        String serviceName = System.getProperty("skywalking.agent.service_name");
        if (StringUtil.isNotEmpty(serviceName)) {
            Agent.SERVICE_NAME = serviceName;
        }

        String instanceName = System.getProperty("skywalking.agent.instance_name");
        if (StringUtil.isNotEmpty(instanceName)) {
            Agent.INSTANCE_NAME = instanceName;
        } else {
            Agent.INSTANCE_NAME = TraceUtils.getHost();
        }

    }
}
